GitHub gpg signing 設定
GitHubのgpg signingを設定する方法
for mac
homebrewでgnupg, pinentry-macをinstallする
以前はgpg-agentが必要だったが、今はgnupgに含まれる
code:sh
$ brew install gnupg
$ brew install pinentry-mac
for windows
winget install GnuPg.GnuPG
gpg-agentで鍵を生成
暗号化方式や鍵の長さなど良しなに設定する
name, email, password を設定
code:sh
$ gpg --full-generate-key
作成した鍵のIDを確認
code:sh
$ gpg --list-secret-keys --keyid-format short
gpg-agentの設定ファイルを更新
for mac
code:sh
$ echo "pinentry-program /opt/homebrew/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
for windows
code:sh
$ echo "pinentry-program 'C:/Program Files (x86)/GnuPG/bin/pinentry-w32.exe'" >> ~\.gnupg\gpg-agent.conf
GitHubに登録する鍵を出力
code:sh
$ gpg --armor --export <id>
GitHubに鍵を登録
https://github.com/settings/gpg/new
gpg-agentを終了する
使用時に自動で再起動する
code:sh
killall gpg-agent
gitconfig (~/.gitconfig)を編集する
3箇所変更する
code:.gitconfig-ebkn
user
email = yyyyy # gpg key 作成時に使用したものと同じもの、かつ GitHub に登録済みのメールアドレス
signingkey = XXXXXX
gpg
program = gpg
commit
...
gpgsign = true
memo: git update-index --assume-unchanged .gitconfig-ebkn, git update-index --skip-worktree .gitconfig-ebkn でgitから無視
動作確認
code:sh
git commit --allow-empty -S -m "test: verify GPG signing"
git log --show-signature -1